home *** CD-ROM | disk | FTP | other *** search
/ Palm Utilities / Palm_Utilities_CD-ROM_2001_2001.iso / files / utils misc / Boxer 0.18 / Boxer018.exe / boxer / LinBoxer / box.c next >
Encoding:
C/C++ Source or Header  |  2000-07-09  |  2.1 KB  |  116 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <time.h>
  4.  
  5. #include <stdlib.h>
  6. #include <netinet/in.h>
  7.  
  8. int main(int argc, char *argv[])
  9. {
  10.  
  11.   unsigned long cofst;
  12.   char bbuf[5000];
  13.   unsigned short xshort;
  14.   unsigned long xlong, xid;
  15.   long bbuflen;
  16.   int maxsect;
  17.   char fname[256];
  18.   FILE *outfd, *infd;
  19.  
  20.   int argp = 1;
  21.  
  22.   if (argc < 2) {
  23.     fprintf(stderr, "Usage: %s inputfile(s)\n", argv[0]);
  24.     exit(1);
  25.   }
  26.  
  27.   while (argp < argc) {
  28.     strcpy(fname, argv[argp++]);
  29.  
  30.     if (!(infd = fopen(fname, "r")))
  31.       exit(-1);
  32.  
  33.     memset(bbuf, 0, 32);
  34.     if (strlen(fname) < 32)
  35.       strcpy(bbuf, fname);
  36.     else
  37.       strcpy(bbuf, &fname[strlen(fname) - 32]);
  38.  
  39.     strcat(fname, ".pdb");
  40.  
  41.     if (!(outfd = fopen(fname, "w")))
  42.       exit(-1);
  43.  
  44.     fwrite(bbuf, 1, 32, outfd);
  45.  
  46.     memset(bbuf, 0, 4);
  47.     bbuf[1] = 0x88;
  48.     bbuf[3] = 1;
  49.     fwrite(bbuf, 1, 4, outfd);
  50.  
  51.     xlong = time(NULL) + ((66 * 365 + 17) * 24 * 3600UL);
  52.     xlong = htonl(xlong);
  53.  
  54.     fwrite(&xlong, 1, 4, outfd);
  55.     fwrite(&xlong, 1, 4, outfd);
  56.     fwrite(&xlong, 1, 4, outfd);
  57.  
  58.     memset(bbuf, 0, 12);
  59.     fwrite(bbuf, 1, 12, outfd);
  60.  
  61.     fwrite("DATA", 1, 4, outfd);
  62.     fwrite("BOXR", 1, 4, outfd);
  63.  
  64.     bbuf[0] = 0x28;
  65.     fwrite(bbuf, 1, 8, outfd);
  66.  
  67.     fseek(infd, 0, SEEK_END);
  68.     xlong = ftell(infd);
  69.     fseek(infd, 0, SEEK_SET);
  70.  
  71.     maxsect = xlong / 4096 + 1;
  72.     xshort = htons(maxsect);
  73.     fwrite(&xshort, 1, 2, outfd);
  74.  
  75.     cofst = 80 + 8 * maxsect;
  76.  
  77.     xid = 0x40000000UL + (rand() & 0x7fffffUL);
  78.  
  79.     strcpy(bbuf, "DBLK");
  80.     bbuf[5] = bbuf[7] = 0;
  81.     bbuf[6] = 0x10;
  82.  
  83.     while (maxsect--) {
  84.       xlong = htonl(cofst);
  85.       fwrite(&xlong, 1, 4, outfd);
  86.       xlong = htonl(xid++);
  87.       fwrite(&xlong, 1, 4, outfd);
  88.       cofst += 4104;
  89.     }
  90.  
  91.     xshort = 0;
  92.     fwrite(&xshort, 1, 2, outfd);
  93.  
  94.     for (;;) {
  95.  
  96.       bbuflen = fread(&bbuf[8], 1, 4096, infd);
  97.  
  98.       if (bbuflen != 4096)
  99.     break;
  100.  
  101.       fwrite(bbuf, 1, bbuflen + 8, outfd);
  102.     }
  103.     if( bbuflen < 0 )
  104.       exit(-3);
  105.  
  106.     fwrite(bbuf, 1, 4, outfd);
  107.     xlong = htonl(bbuflen);
  108.     fwrite(&xlong, 1, 4, outfd);
  109.     fwrite(&bbuf[8], 1, bbuflen, outfd);
  110.  
  111.     fclose(infd);
  112.     fclose(outfd);
  113.   }
  114.   return 0;
  115. }
  116.